package com.example.demo.service;

import com.example.demo.dao.NoticeDao;

import com.example.demo.entity.Notice;
import com.example.demo.entity.Params;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class NoticeService {

    @Resource
    private NoticeDao noticeDao;

    public  PageInfo<Notice> findBySearch(Params params) {
        //开启分页查询
        PageHelper.startPage(params.getPageNum(),params.getPageSize());
        List<Notice> bySearch = noticeDao.findBySearch(params);
        return PageInfo.of(bySearch);
    }
    public void add(Notice notice) {
        noticeDao.insertSelective(notice);
    }
    public void update(Notice notice) {
        noticeDao.updateByPrimaryKeySelective(notice);
    }

    public void delete(Integer id) {
       noticeDao.deleteByPrimaryKey(id);
    }

    public List<Notice> findAll() {
        return noticeDao.selectAll();
    }
}
